<?php
class hrd_asuransi_triwulan_model extends MY_Model {
	var $nama_tabel = 'hrd_asuransi_triwulan';
	
	function GetJSON() {
		$ls_sql	= "	SELECT	a.*, b.nama_karyawan, c.nama_periode
					FROM	".$this->nama_tabel." a
					LEFT JOIN hrd_karyawan b ON a.id_karyawan_fk = b.id_karyawan_pk
					LEFT JOIN hrd_periode c ON a.id_periode_fk = c.id_periode_pk
					WHERE id_karyawan_fk LIKE '%".post('id_karyawan_cari')."%'
					AND id_periode_fk = '".post('id_periode_cari')."'
					ORDER BY ".(post('sort')=='' ? 'id_asuransi_triwulan_pk' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
					
		return json_encode( $this->paging($ls_sql) );
	}

	function GetImportJSON() {
		$ls_sql	= "	SELECT	a.*, b.nama_karyawan, c.nama_periode
					FROM	".$this->nama_tabel." a
					LEFT JOIN hrd_karyawan b ON a.id_karyawan_fk = b.id_karyawan_pk
					LEFT JOIN hrd_periode c ON a.id_periode_fk = c.id_periode_pk
					WHERE (
							id_karyawan_fk LIKE '%".post('keyword')."%'
							OR
							UPPER(b.nama_karyawan) LIKE '%".strtoupper(post('keyword'))."%'
						)
					AND id_periode_fk = '".post('id_periode_cari_2')."'
					ORDER BY ".(post('sort')=='' ? 'id_asuransi_triwulan_pk' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
					
		return json_encode( $this->paging($ls_sql) );
	}

	function Add($arr_data){
		$this->db->insert($this->nama_tabel, $arr_data);
	}

	function Update($arr_data, $arr_rule){
		$this->db->update($this->nama_tabel, $arr_data, $arr_rule);
	}

	function DeleteSingle($arr_rule) {
		try {
			$this->db->delete($this->nama_tabel, array('id_asuransi_triwulan_pk' => $arr_rule['id_asuransi_triwulan_pk']));
			return '';
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}

}
?>